﻿using System;
using OpenTK;

namespace Mono.Rift.Core.Graphics
{
	public abstract class RenderDevice
	{
		public Shader[] VertexShaders { get; set; }
		public Shader[] Shaders { get; set; }
		public Shader[] FragmentShaders { get; set; }
		public Matrix4 Projection { get; set; }

		public Action OnLoad { get; set; }
		public Action OnResize { get; set; }
		public Action UpdateFrame { get; set; }
		public Action RenderFrame { get; set; }

		public Buffer LightingBuffer { get; set; }

		public RenderDevice ()
		{
		}

		public virtual void beginScene() 
		{
			beginRendering ();
		}

		public virtual void setProjection(Matrix4 projection)
		{
			Projection = projection;
			setWorldUniforms (Projection);
		}

		public abstract void beginRendering();

		public abstract void setViewport (int x, int y, int width, int height);
		public abstract void present ();
		public abstract void setWorldUniforms(Matrix4 projection);
		public abstract void clear(float r = 0.0f, float g = 0.0f, float b = 0.0f, float a = 1.0f, double depth = 1.0f);
		public abstract void setDepthMode(bool enable, bool write, CompareFunc func = CompareFunc.Less);

		public abstract void run(double frameRate);

		public abstract void render(Matrix4 matrix, Model model);

		public virtual void setLighting(LightingParams lightingParams)
		{
			if (LightingBuffer == null)
			{
				LightingBuffer = createBuffer ();
			}
			LightingBuffer.Data = lightingParams;
			setCommonUniformBuffer (1, LightingBuffer);
		}

		public abstract Buffer createBuffer();
		public virtual void setCommonUniformBuffer(int i, Buffer buffer) { }
	}
}

